package com.classroom.langchain.demo.aiservice;

import dev.langchain4j.model.chat.listener.ChatModelErrorContext;
import dev.langchain4j.model.chat.listener.ChatModelListener;
import dev.langchain4j.model.chat.listener.ChatModelRequestContext;
import dev.langchain4j.model.chat.listener.ChatModelResponseContext;
import dev.langchain4j.model.chat.request.ChatRequest;
import dev.langchain4j.model.chat.response.ChatResponse;
import lombok.extern.slf4j.Slf4j;

import java.util.UUID;

@Slf4j
public class TestChatModelListener implements ChatModelListener {

   public void onRequest(ChatModelRequestContext requestContext) {
       log.info("onRequest: {}", requestContext.chatRequest());
       UUID uuid = UUID.randomUUID();
       requestContext.attributes().put("uuid", uuid);
       log.error("====onRequest============uuid: {}", uuid);
    }

    public void onResponse(ChatModelResponseContext responseContext) {
        Object uuid = responseContext.attributes().get("uuid");
        log.error("====onResponse============uuid: {}", uuid);

    }

    public void onError(ChatModelErrorContext errorContext) {

    }
}
